<?php
namespace app\api\model;
use think\Model;
use think\Db;
class  QrCode extends  Model{
    // 设置当前模型对应的完整数据表名称
        protected $table = 'gx_qr_code';
        protected $createTime = false;
        public function add($data){
            try {
               $res=$this->save($data);
               if($res){
                   return $this->id;
               }else {
                   return 0;
               }
            }catch (\think\Exception $e){
                trace('insert failed'.$e->getMessage());
            }
        }
        //获取用户预约场地的费用和系数
        public function getFeeAndX($where){
            try {
               $res= Db::name('gx_venue_status')->field('fee,xishu')
                ->where($where)->find();
               dump($res);
               if(!empty($res)){
                   return $res;
               }else{
                   return 0;
               }
            }catch (\think\Exception $e){
                trace('select failed'.$e->getMessage());
            }
        }
        //
        public function getUserNickName($user_id){
            try {
                $res=Db::name('cuser_info')->where(array('uid'=>$user_id))->field('nickname')->find();
                if(!empty($res)){
                    return $res['nickname'];
                }else{
                    return 0;
                }
            }catch (\think\Exception $e){
                trace('select failed'.$e->getMessage());
            }
        }
        //就需要对这个数组进行重新组合
        public function getAppointInfo()
        {
            
        }
        //点击查询用户二维码是否生成如果有输出
        public function selectQrCode($where){
           $res= Db::name('qr_code')
           ->field(array('qr_code_address','status','create_time','id','endtime','place_id','appoint_time','riqi'))
           ->where(array('uid'=>$where['uid'],'place_id'=>$where['place_id'],'appoint_time'=>$where['appoint_time'],'riqi'=>$where['riqi']))
           ->find();
           
           return $res;
        }
        public function selectItemAdress($id){
           $res= Db::name('qr_code')->field('qr_code_address')
      ->where('id',$id)
      ->find();
           return $res;
        }
        
//     public function updatestatus($id){
//         $this->where('id',$id)->update(array('status'))
//     }
public function selectQrcodeById($id)
{
    $res=Db::name('qr_code')->where('id',$id)->field(array('qr_code_address','status','create_time','id','endtime','place_id','appoint_time','riqi'))->find();
    return $res;
}
//修改二维码的状态
public function updatestatus($where,$endtime){
    $res=Db::name('qr_code')->where($where)
    ->update(array('status'=>1,'endtime'=>$endtime));
    return $res;
}
}